﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DetectiveCluedo
{
    public partial class MDIParent1 : Form
    {
        public MDIParent1()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            NewGameForm ngf = new NewGameForm();
            ngf.MdiParent = this;
            ngf.Show();
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void suspectsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CardEditorForm cef = new CardEditorForm(ECardType.Suspect);
            cef.MdiParent = this;
            cef.Show();
        }

        private void weaponsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CardEditorForm cef = new CardEditorForm(ECardType.Weapon);
            cef.MdiParent = this;
            cef.Show();
        }

        private void roomsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CardEditorForm cef = new CardEditorForm(ECardType.Room);
            cef.MdiParent = this;
            cef.Show();
        }

        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string[] p = new string[] { "Ms Scarlet", "Col Mustard", "Mr Green", "Mrs Peacock", "Prof Plum" };
            CluedoGame.CreatePlayers(p);

            bool b = CluedoGame.SetYourself("Mr Green");

            List<Card> checkedCards = new List<Card>();

            checkedCards.Add(new Card() { Name = "Prof Plum", Type = ECardType.Suspect });
            checkedCards.Add(new Card() { Name = "Rope", Type = ECardType.Weapon });
            checkedCards.Add(new Card() { Name = "Lounge", Type = ECardType.Room });
            checkedCards.Add(new Card() { Name = "Library", Type = ECardType.Room });

            foreach (Card card in checkedCards)
            {
                CluedoGame.SetPlayersCardInfo(CluedoGame.GetYourself(), card, true, EPlayerCardInfoStatusReason.MyCard);
            }

            // add moves

            CluedoGame.AddGameLog(new GameLog(
                CluedoGame.GetPlayerByName("Ms Scarlet"),
                CluedoGame.GetPlayerByName("Mr Green"),
                CluedoGame.GetCardByNameAndType("Col Mustard", ECardType.Suspect),
                CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon),
                CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
                CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room)
            ));

            CluedoGame.AddGameLog(new GameLog(
                CluedoGame.GetPlayerByName("Col Mustard"),
                CluedoGame.GetPlayerByName("Mr Green"),
                CluedoGame.GetCardByNameAndType("Col Mustard", ECardType.Suspect),
                CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon),
                CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
                CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room)
            ));

            CluedoGame.AddGameLog(new GameLog(
         CluedoGame.GetPlayerByName("Mrs Peacock"),
         CluedoGame.GetPlayerByName("Prof Plum"),
         CluedoGame.GetCardByNameAndType("Ms Scarlet", ECardType.Suspect),
         CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
         CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room),
         null));

            CluedoGame.AddGameLog(new GameLog(
            CluedoGame.GetPlayerByName("Ms Scarlet"),
            CluedoGame.GetPlayerByName("Col Mustard"),
            CluedoGame.GetCardByNameAndType("Mrs Peacock", ECardType.Suspect),
            CluedoGame.GetCardByNameAndType("Revolver", ECardType.Weapon),
            CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room),
            null));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mr Green", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Mr Green", ECardType.Suspect)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetCardByNameAndType("Mr Green", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Kitchen", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mr Green", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Candlestick", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetCardByNameAndType("Col Mustard", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Revolver", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Dining Room", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetCardByNameAndType("Col Mustard", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Revolver", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Dining Room", ECardType.Room),
               null
           ));


            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetCardByNameAndType("Mrs Peacock", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Candlestick", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Study", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetCardByNameAndType("Ms Scarlet", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Candlestick", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mrs Peacock", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mr Green", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Wrench", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Ballroom", ECardType.Room)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mrs Peacock", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Wrench", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Ms Scarlet", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Billiard Room", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Revolver", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Dining Room", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Dining Room", ECardType.Room)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Lounge", ECardType.Room)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Conservatory", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetCardByNameAndType("Ms Scarlet", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Library", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Library", ECardType.Room)
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               null,
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Rope", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Hall", ECardType.Room),
               null
           ));

            
            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mrs Peacock"),
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetCardByNameAndType("Prof Plum", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Lead Pipe", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Hall", ECardType.Room),
               null
           ));
            
            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetPlayerByName("Col Mustard"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Candlestick", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Hall", ECardType.Room),
               null
           ));
            /*
            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetPlayerByName("Prof Plum"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Knife", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Hall", ECardType.Room),
               null
           ));

            CluedoGame.AddGameLog(new GameLog(
               CluedoGame.GetPlayerByName("Mr Green"),
               CluedoGame.GetPlayerByName("Ms Scarlet"),
               CluedoGame.GetCardByNameAndType("Mrs White", ECardType.Suspect),
               CluedoGame.GetCardByNameAndType("Wrench", ECardType.Weapon),
               CluedoGame.GetCardByNameAndType("Study", ECardType.Room),
               CluedoGame.GetCardByNameAndType("Study", ECardType.Room)
           ));
            */

            CluedoGame.Investigate();

            var ggf = new GameGridForm();
            ggf.MdiParent = this;
            ggf.Show();

            var glf = new GameLogForm();
            glf.MdiParent = this;
            glf.Show();

            LayoutMdi(MdiLayout.TileVertical);
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CluedoGame.Save())
                toolStripStatusLabel1.Text = "Game saved successfully.";
            else
                toolStripStatusLabel1.Text = "Game couldn't be saved!";
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CluedoGame.Open())
            {

                //CluedoGame.Investigate();

                var ggf = new GameGridForm();
                ggf.MdiParent = this;
                ggf.Show();

                var glf = new GameLogForm();
                glf.MdiParent = this;
                glf.Show();

                LayoutMdi(MdiLayout.TileVertical);
            }
        }
    }
}
